PWD := $(shell pwd)

obj-m := tdm-verify.o
tdm-verify-objs := tdm_verify.o

#if  LOCAL_KERDIR exist,use  LOCAL_KERNEL path
ifeq ($(LOCAL_KERDIR),)
ifeq ("$(origin KERNVER)", "command line")
  KBUILD_VERSION = $(KERNVER)
else
  ifeq ($(filter clean distclean, $(MAKECMDGOALS)),)
    $(error "build log driver needs assign linux kernel !")
  endif
endif
endif

# for ubuntu, module build top tree is the kernel directory in the build source directory
#        e.g.
#             kernel-4.15.4.symlink     -> ./kernel-4.15.4/
# for centos, module build top tree is the kernel directory under ~/rpmbuild/BUILD/kernel-?
#        e.g.
#             kernel-3.10.0-957.symlink -> ~/rpmbuild/BUILD/kernel-3.10.0_957_sev/
#if  LOCAL_KERDIR exist,use  LOCAL_KERNEL path
ifeq ($(LOCAL_KERDIR),)
KERNELDIR := ../../../../../kernel-$(KBUILD_VERSION).symlink
else
KERNELDIR=$(LOCAL_KERDIR)
endif

default:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
	-rm -rf $(shell find -L . -name "*.o.cmd" \
		-o -name "*.o" \
		-o -name "*.ko" \
		-o -name "*.o.d" \
		-o -name "*.mod.c" \
		-o -name "*.ko.cmd" \
		-o -name ".tmp_versions")
	-rm -f modules.order Module.symvers

distclean: clean
	-rm -rf $(shell find -L . -name "*.ko")
